package com.cya.lotterysystem.dao.mapper;

import com.cya.lotterysystem.dao.dataobject.Encrypt;
import com.cya.lotterysystem.dao.dataobject.UserDo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author ：陈奕安（3048279304@qq.com）
 * @date ：Created in 2025/10/28 19:32
 * @description：
 * @modified By：
 * @version:
 */
@Mapper
public interface UserMapper {

    @Select("select count(*) from user where email =#{email}")
    int countByMail(@Param("email") String email) ;

    @Select("select count(*) from user where  phone_number=#{phoneNumber} ")
    int countByPhone(@Param("phoneNumber") Encrypt phoneNumber);

    @Insert("insert into user (user_name,email,phone_number,password,identity) values (#{userName},#{email},#{phoneNumber},#{password},#{identity});")
    //useGeneratedKeys表示使用默认生成的主键,keyProperty表示id为主键,keyColumn列名为id
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert(UserDo userDo);

    @Select("select* from user where email=#{email}")
    UserDo selectByMail(@Param("email") String emali);

    @Select("select* from user where phone_number=#{phoneNumber}")
    UserDo selecyByPhoneNumber(@Param(("phoneNumber")) Encrypt encrypt);


    /**
     * 倒叙查找
     * @param identity
     * @return
     */
    @Select("<script>" +
            " select * from user" +
            " <if test=\"identity!=null\">" +
            " where identity=#{identity}" +
            " </if>" +
            " order by id desc" +
            " </script>")
    List<UserDo> selectUserInfoByIdentity(@Param("identity") String identity);

@Select("<script>" +
        " select id from user" +
        " where id in" +
        " <foreach item='item' collection='items' open='(' separator=',' close=')'>"+
        " #{item}" +
        " </foreach>" +
        " </script>")
    List<Long> selectExistByIds(@Param("items") List<Long> id);

    @Select("<script>" +
            " select * from user" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>"+
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<UserDo> batchSelectByIds(@Param("items") List<Long> ids);
}